using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;

namespace WebControls
{
   public class SFCheckBox:CheckBox, IReadOnly, IClear, ILabel, IValidation,IMultiLanguage
    {
       public SFCheckBox()
        {
            StaticMethods.AddAttributes(this);
            
        }
       protected override void OnLoad(EventArgs e)
       {
           List<SFLabel> lblRetval = StaticMethods.GetLabel(this);
           if(lblRetval!=null)
           {
           foreach (SFLabel lbl in lblRetval)
           {
               if (this.AllowNull)
               {
                   lbl.CssClass = "cssLabelNormal";
               }
               else
               {
                   lbl.CssClass = "cssLabelRequired";
               }
           }
           }
           base.OnLoad(e);
       }

       #region IValidation Members

       private bool _AllowNull = true;
       
       public bool AllowNull
       {
           get
           {
               return _AllowNull;
           }
           set
           {
               _AllowNull = value;
           }
       }
       private bool _HasErrors = false;

      
       public bool HasErrors
       {
           get { return _HasErrors; }
       }

       private string _ErrorMessage = "";
       
       public string ErrorMessage
       {
           get
           {
               return _ErrorMessage;
           }
           set
           {
               _HasErrors = (value != "");
               _ErrorMessage = value;
           }
       }

       public virtual bool Validate()
       {
           if (!AllowNull && this.Visible)
           {
               if (!this.Checked)
               {
                  
                   this.ErrorMessage += StaticMethods.GetErrorMessageMultilanguageString(16, new object[] { StaticMethods.GetErrorMessageControlName(this) });
               }
           }

           return this.HasErrors;
       }
       #endregion

       #region ILabel Members

       private string _ControlsLabel;
      
       public string ControlsLabel
       {
           get
           {
               return _ControlsLabel;
           }
           set
           {
               _ControlsLabel = value;
           }
       }

       #endregion

       #region IClear Members

       public void Clear()
       {
           this.Checked = false;
       }

       #endregion

       #region IReadOnly Members

       public bool ReadOnly
       {
           get
           {
               return !this.Enabled;
           }
           set
           {
               this.Enabled = !value;
           }
       }

       #endregion

       public bool? Value
       {
           get { return this.Checked; }
           set { this.Checked = value.Value; }
       }

       public object Tag
       {
           get { return ViewState["Tag"]; }
           set { ViewState["Tag"] = value; }
       }

       #region IMultiLanguage Members

       public void SetControlLanguage()
       {
           string txt = StaticMethods.GetMultilanguageString(this);
           if (txt != "")
           {
               this.Text = txt;
           }
       }
       private bool _IsProtectedForLanguageChange = false;
       public bool IsProtectedForLanguageChange
       {
           get
           {
               return _IsProtectedForLanguageChange;
           }
           set
           {
               _IsProtectedForLanguageChange = value;
           }
       }

       private bool _IsMasterPageControl = false;
       public bool IsMasterPageControl
       {
           get
           {
               return _IsMasterPageControl;
           }
           set
           {
               _IsMasterPageControl = value;
           }
       }

       #endregion
   }
}

